var checkForm = function(){
	var $pwd = $("#input_password");
	var $oldPwd = $("#input_oldPassword");
	var $rePwd = $("#input_rePassword");
	if($oldPwd.val().length==0){
		$oldPwd.focus();
		layer.tips("请输入原密码","#input_oldPassword");
		return false;
	}
	if($pwd.val()==""){
		$pwd.focus();
		layer.tips("请输入新密码","#input_password");
		return false;
	}else if(!/.{6,16}/.test($pwd.val())){
		$pwd.focus();
		layer.tips("请输入6-16位新密码","#input_password");
		return false;
	}
	
	if($pwd.val()==$oldPwd.val()){
		layer.alert("新密码不要和原密码相同",{icon:0});
		return false;
	}
	
	if($rePwd.val().length==0){
		$rePwd.focus();
		layer.tips("请输入确认密码","#input_rePassword");
		return false;
	}else if($rePwd.val()!=$pwd.val()){
		$rePwd.focus();
		layer.tips("两次密码不一致","#input_rePassword");
		return false;
	}
	return true;
}
var upperCase= new RegExp('[A-Z]');
var lowerCase= new RegExp('[a-z]');
var numbers = new RegExp('[0-9]');
var specialchars = new RegExp('([!,%,&,@,#,$,^,*,?,_,~])');
function check_strength(thisval){
	 var characters = 0;
	 var capitalletters = 0;
	 var loweletters = 0;
	 var number = 0;
	 var special = 0;
   if (thisval.length > 6) { characters = 1; } else { characters = 0; };
   if (thisval.match(upperCase)) { capitalletters = 1} else { capitalletters = 0; };
   if (thisval.match(lowerCase)) { loweletters = 1}  else { loweletters = 0; };
   if (thisval.match(numbers)) { number = 1}  else { number = 0; };
   return characters + capitalletters + loweletters + number + special;
}

$(function(){
	$("#input_password").bind('keyup keydown', function(event) {
	   var val = this.value;
	   if(val.length>16 && event.keyCode!=8){
		   return false;
	   }
	   var $this = $(this);
	   var total = check_strength(val);
	   var $p =  $this.next();
	   if(total == 0){
		   //$p.removeClass();
		   $p.text("");
      }else if (total <= 1) {
    	  //$p.text("密码强度: 很弱").addClass('veryweak');
    	  $p.text("密码强度: 很弱");
      } else if (total == 2){
    	  //$p.removeClass().addClass('weak').text("密码强度: 较弱");
    	  $p.text("密码强度: 较弱");
      } else if(total == 3){
    	  //$p.removeClass().addClass('medium').text("密码强度: 一般");
    	  $p.text("密码强度: 一般");
      } else {
    	  //$p.removeClass().addClass('strong').text("密码强度: 较强");
    	  $p.text("密码强度: 较强");
      } 
	});
});